package com.hlkj.action.main;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import com.easy.tool.results.ResultParameters;
import com.hlkj.tool.results.JsonBulid;
import com.hlkj.util.SQLFactory;

public class LeftAction {

	public String left() {
		return "left";
	}
	
	public String getList() {
		//http://127.0.0.1:8080/struts2_jdbc_5_30/main/getList
		ArrayList<Map<String, Object>> menuList = new ArrayList<Map<String, Object>>();
		try {
			String sql = "SELECT T2.MENU_ID, T2.P_ID, T2.MENU_NAME, T2.URL, T2.TARGET, T2.IS_OPEN FROM SYS_MENU T2 ORDER BY T2.SORT";
			List<Map<String, Object>> list = SQLFactory.queryList(sql);
			Map<String, Object> map = null;

			for (int i = 0; i < list.size(); i++) {
				map = new HashMap<String, Object>();
				map.put("id", list.get(i).get("menu_id"));
				map.put("pId", list.get(i).get("p_id"));
				map.put("name", list.get(i).get("menu_name"));
				if (list.get(i).get("url") != null) {
					map.put("url", list.get(i).get("url"));
				}
				if (list.get(i).get("target") != null) {
					map.put("target", list.get(i).get("target"));
				}
				map.put("open", list.get(i).get("is_open"));
				menuList.add(map);
			}
			JSONArray jsonArray = JSONArray.fromObject(menuList);
			ResultParameters.setJson(JsonBulid.success(true).msg("操作成功!").add("menuList", jsonArray).json());
		} catch (Exception e) {
			e.printStackTrace();
			ResultParameters.setJson(JsonBulid.success(true).msg("操作失败!").json());
		}
		// new Gson().toJson(menuList);
		return ResultParameters.JSON;
	}
}
